w=0
def p(x):
    k=0
    for i in range(2,x):
        if x%i==0:
            k+=1
    if k==0:
        return True
    else:
        return False
s=input().split()
d=["zero","one","two","three","four","five", "six","seven","eight","nine"]
if len(s)==3 and s[0] in d and s[0]!="zero" and s[1] in d and s[2] in d :
    a=d.index(s[0])
    b=d.index(s[1])
    c=d.index(s[2])
    x=100*a+10*b+c
    for j in range(0,x*2):
        if p(x-j)==True:
            w=x-j
            break
        if p(x+j)==True:
            w=x+j
            break
else:
    print("Wrong input")
print(w)
